package com.sample.traffic.action.tcccx;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sample.traffic.action.tcccx.dao.tccszGisDao;

public class tccszGisAction extends ActionSupport {
	
	
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		ActionContext ctx = ActionContext.getContext();         
		HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
		tccszGisDao dao = new tccszGisDao();
		request.setAttribute("nodeList",dao.getNodeInfo());
		request.setAttribute("areaList",dao.getAreaInfo());
		return SUCCESS;
	}
	
	public String addArea() throws Throwable {
		ActionContext ctx = ActionContext.getContext();         
		HttpServletRequest p_request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
		String node = java.net.URLDecoder.decode(p_request.getParameter("node"),"UTF-8");
		String area = p_request.getParameter("area");
		String areaName =java.net.URLDecoder.decode(p_request.getParameter("areaName") , "UTF-8");
		String qxdj = p_request.getParameter("qxdj");
		tccszGisDao dao = new tccszGisDao();
		boolean flag = false;
		flag=dao.insertArea(node,area,areaName,qxdj);
		HttpServletResponse p_response = ServletActionContext.getResponse(); 
		PrintWriter out = p_response.getWriter();
		out.print(String.valueOf(flag));
		return null;
	}
	
	public String updateArea() throws Throwable {
		ActionContext ctx = ActionContext.getContext();         
		HttpServletRequest p_request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
		String area = p_request.getParameter("area");
		String areaName = java.net.URLDecoder.decode(p_request.getParameter("areaName") , "UTF-8");
		String qxdj = p_request.getParameter("qxdj");
		tccszGisDao dao = new tccszGisDao();
		boolean flag = false;
		flag=dao.updateArea(area,areaName,qxdj);
		HttpServletResponse p_response = ServletActionContext.getResponse(); 
		PrintWriter out = p_response.getWriter();
		out.print(String.valueOf(flag));
		return null;
	}
	
	public String delArea() throws Throwable {
		ActionContext ctx = ActionContext.getContext();         
		HttpServletRequest p_request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
		String area = p_request.getParameter("area");
		tccszGisDao dao = new tccszGisDao();
		boolean flag = true;
		dao.delArea(area);
		HttpServletResponse p_response = ServletActionContext.getResponse(); 
		PrintWriter out = p_response.getWriter();
		out.print(String.valueOf(flag));
		return null;
	}
}
